﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;

namespace Itfort.Web
{
	/// <summary>
	/// 页面基类
	/// </summary>
	public class PageBase : Page
	{
		/// <summary>
		/// 页面结果
		/// </summary>
		public PageResult Result { get; set; }

		protected override void OnInit(EventArgs e)
		{
			base.OnInit(e);
			this.Result = new PageResult();
		}

		protected override void OnLoad(EventArgs e)
		{
			base.OnLoad(e);
			this.RegisterHttpMethodProcess();
		}

		protected void RegisterHttpMethodProcess()
		{
			switch (Request.HttpMethod)
			{
				case "GET":
					this.HttpGetProcess();
					break;
				case "POST":
					this.HttpPostProcess();
					break;
				case "PUT":
					this.HttpPutProcess();
					break;
				case "DELETE":
					this.HttpDeleteProcess();
					break;
				case "HEAD":
					this.HttpHeadProcess();
					break;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		protected virtual void HttpGetProcess() { }

		/// <summary>
		/// 
		/// </summary>
		protected virtual void HttpPostProcess() { }

		/// <summary>
		/// 
		/// </summary>
		protected virtual void HttpPutProcess() { }

		/// <summary>
		/// 
		/// </summary>
		protected virtual void HttpDeleteProcess() { }

		/// <summary>
		/// 
		/// </summary>
		protected virtual void HttpHeadProcess() { }
	}

	/// <summary>
	/// 页面基类
	/// </summary>
	/// <typeparam name="T"></typeparam>
	public class PageBase<T> : PageBase
	{
		/// <summary>
		/// 模型对象
		/// </summary>
		public T Model { get; set; }

		protected override void OnInit(EventArgs e)
		{
			base.OnInit(e);
			Model = Activator.CreateInstance<T>();
		}
	}
}